package com.music.user.controller.web;

import com.music.common.core.domain.R;
import com.music.common.core.web.controller.BaseController;
import com.music.common.core.web.domain.AjaxResult;
import com.music.common.core.web.page.TableDataInfo;
import com.music.common.security.annotation.InnerAuth;
import com.music.common.security.annotation.RequiresPermissions;
import com.music.user.domain.User;
import com.music.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户列表Controller
 *
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/user")
public class UserWebController extends BaseController {
    @Autowired
    private UserService userService;

    @InnerAuth
    @GetMapping("web")
    public R<User> getInfo(@RequestParam("userAccount") String userAccount, @RequestParam("userPassword") String userPassword) {
        return R.ok(userService.getInfo(new User(userAccount, userPassword)));
    }

    @InnerAuth
    @PostMapping("web")
    public void add(@RequestBody User user) {
        userService.insertUser(user);
    }

    @InnerAuth
    @GetMapping("/web/findUserByAccount")
    public R<User> findUserByAccount(@RequestParam("userAccount") String userAccount) {
        return R.ok(userService.getInfo(new User(userAccount)));
    }

    @GetMapping("/web/list")
    public TableDataInfo list(User user) {
        startPage();
        List<User> list = userService.selectUserList(user);
        return getDataTable(list);
    }


}
